package com.quotes.simulation;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;

public class PortfolioChangedEvent
{
	private String message;
	private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
	private DecimalFormat numberFormat = new DecimalFormat("#0.00");
	
	public void buyEvent(MarketOrder buyOrder, double currentCash) {
		message = dateFormat.format(buyOrder.getDate()) + ": Buy " + buyOrder.getCount() + " * " + 
				buyOrder.getSymbol() + " for " + numberFormat.format(buyOrder.getPrice()) + " Euro. " +
				"Volume=" + numberFormat.format(buyOrder.getValue()) + " Euro. " +
				"StopLoss=" + numberFormat.format(buyOrder.getStopLossPrice()) + " Euro. " +
				"CashLeft=" + numberFormat.format(currentCash) + "Euro.";
	}
	
	public void sellEvent(MarketOrder buyOrder, MarketOrder sellOrder, double currentCash) {
		double earnings = sellOrder.getValue() - buyOrder.getValue();

		if (earnings >= 0)
			message = dateFormat.format(sellOrder.getDate()) + ": WIN " + numberFormat.format(earnings) + " Euro: ";
		else 
			message = dateFormat.format(sellOrder.getDate()) + ": LOST " + numberFormat.format(earnings) + " Euro: ";
		
		message += "Sell " + sellOrder.getCount() + " * " + 
				sellOrder.getSymbol() + " for " + numberFormat.format(sellOrder.getPrice()) + " Euro. " +
				"Volume=" + numberFormat.format(sellOrder.getValue()) + " Euro. " +
				"CashLeft=" + numberFormat.format(currentCash) + " Euro. " + 
				"ADX=" + numberFormat.format(buyOrder.getInfo("adx")) + ". " + 
				"RSI=" + numberFormat.format(buyOrder.getInfo("rsi")) + ". " + 
				"DI+=" + numberFormat.format(buyOrder.getInfo("diplus")) + ". " + 
				"DI-=" + numberFormat.format(buyOrder.getInfo("diminus"));
	}
	
	public String toString() {
		return message;
	}
}